/*
 * Copyright (C) 2015-2016  Nicola Spanti (RyDroid) <dev@nicola-spanti.info>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */


/**
 * @file
 * @brief Struct and functions to manage a RGB color.
 */


#ifndef PLANET_WARS_2D_RT_CORE_COLOR_RGB_ESSENTIAL_H
#define PLANET_WARS_2D_RT_CORE_COLOR_RGB_ESSENTIAL_H


#include "PlanetWars2dRT-core/utils/c_language.h"
#include "PlanetWars2dRT-core/utils/bool.h"


EXTERN_C_BEGIN


struct color_rgb
{
  unsigned char red;
  unsigned char green;
  unsigned char blue;
};
typedef struct color_rgb color_rgb;


#define COLOR_RGB_INVERSE(a_color)				\
  do								\
    {								\
      (a_color).red   = (unsigned char) 255 - (a_color).red;	\
      (a_color).green = (unsigned char) 255 - (a_color).green;	\
      (a_color).blue  = (unsigned char) 255 - (a_color).blue;	\
    }								\
  while(false);


static inline
bool
color_rgb_equals(color_rgb c1, color_rgb c2)
{
  return
    c1.red   == c2.red   &&
    c1.green == c2.green &&
    c1.blue  == c2.blue;
}

static inline
void
color_rgb_inverse(color_rgb* a_color)
{
  COLOR_RGB_INVERSE(*a_color)
}

static inline
color_rgb
get_color_rgb_inversed(color_rgb a_color)
{
  COLOR_RGB_INVERSE(a_color);
  return a_color;
}


EXTERN_C_END


#endif
